import { defineStore } from 'pinia';
import type { AuthState } from "../interface";
import type { RouteRecordRaw } from 'vue-router';
import piniaPersistConfig from '@/store/helper/piniaPersist';
import { getAuthMenuListApi } from '@/api/login';
import { getFlatMenuList,getShowMenuList } from "@/utils/util";

export const useAuthStore = defineStore({
  id: 'authStore',
  state: (): AuthState => ({
    buttonLists:[],
    menuLists:[],
    isRouteFresh:true
  }),
  getters:{
    flatMenuListGet: state => getFlatMenuList(state.menuLists),
    // 菜单权限列表 ==> 这里的菜单没有经过任何处理
    authMenuListGet: state => state.menuLists,
    // 菜单权限列表 ==> 左侧菜单栏渲染，需要剔除 isHide == true
    showMenuListGet: state => getShowMenuList(state.menuLists),
  },
  actions: {
    getAuthMenuList() {
      const { data } = getAuthMenuListApi();
      this.menuLists = data;
    },
  },
  persist: piniaPersistConfig('authStore'),
});
